package com.wavecoler.coach.objects;

import com.wavecoler.professor.objects.Problem;

import java.util.ArrayList;
import java.util.List;

import com.google.appengine.api.datastore.Key;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Element;

@PersistenceCapable
public class Graph {
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key graphId;
	
	@Persistent
	private String graphName;
	
	@Persistent
	private boolean isExpert;
	
	@Persistent
	private String problemId;
	
    @Persistent
    private Problem problem;
      
	
	@Persistent
	private String creator; //tomando como asumption que el que creo la wavelet creo tmb el diagrama
	
	@Persistent(mappedBy = "graph")
	//@Element(dependent = "true")
    private List<Node> nodes = new ArrayList<Node>();

	
	//Getters & Setters 
	public Key getGraphId() {
		return graphId;
	}

	public String getGraphName() {
		return graphName;
	}

	public void setGraphName(String graphName) {
		this.graphName = graphName;
	}

	public boolean isExpert() {
		return isExpert;
	}

	public void setExpert(boolean isExpert) {
		this.isExpert = isExpert;
	}
	
	public void setProblem(Problem problem) {
		this.problem = problem;
	}

	public Problem getProblem() {
		return problem;
	}


	public List<Node> getNodes() {
		return nodes;
	}

	public void setNodes(List<Node> nodes) {
		this.nodes = nodes;
	}
	
	public List<Node> getNodesByType(String type){
		List <Node> nodes = getNodes();
		List<Node> nodeByType = new ArrayList<Node> ();
		for (int i = 0; i < nodes.size(); i++){
			if(nodes.get(i).getType().equals(type.toLowerCase())){
				nodeByType.add(nodes.get(i));
			}
			
		}
		return nodeByType;
		
	}
	
	public Node getNodesByWaveId(String id){
		List <Node> nodes = getNodes();
		Node nodeById = new Node();
		for (int i = 0; i < nodes.size(); i++){
			if(nodes.get(i).getNodeWaveId().equals(id.toLowerCase())){
				nodeById  = nodes.get(i);
			}
			
		}
		return nodeById;
	}
	
	
	//Constructors
	public Graph(String graphName, String creator) {
		super();
		this.graphName = graphName;
		this.creator = creator;
	}
	
	public Graph(String graphName) {
		super();
		this.graphName = graphName;
	}
	
	public Graph(String graphName, String creator, boolean isExpert) {
		super();
		this.graphName = graphName;
		this.creator = creator;
		this.isExpert = isExpert;
	}

	public Graph() {
		super();
	}


	
}
